function M = selectByContact(M1,M2)
% M1, M2: masks
% M: objects in M1 that *DO* touch objects in M2

s = regionprops(M1,M2,'MaxIntensity','PixelIdxList');

mi = cat(1, s.MaxIntensity);

idx = find(mi == 1);

M = zeros(size(M1));
for i = 1:length(idx)
    pidx = s(idx(i)).PixelIdxList;
    M(pidx) = true;
end
M = M > 0;

end